<!DOCTYPE html>
<html lang="zh-cn">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
	<title>登陆</title>

	<link href="__ROOT__/static/css/bootstrap.min.css" rel="stylesheet" />
	<link href="__ROOT__/static/css/common.css" rel="stylesheet" />
	<link href="__ROOT__/static/index/wxgzh/css/index.css" rel="stylesheet" />
	<style>
	</style>

</head>

<body>
	<h6>小程序前端:</h6>
	&lt;button bindtap="login"&gt;登陆获得openid&lt;/button&gt;
	<hr/>
	<h6>前端 js 部分</h6>
	<pre>
	Page({
		//login来自页面button绑定的监听
		login: function() {
		  wx.login({
			success: function(res) {
			 // console.log(res.code)
			  wx.request({
				url: 'https://www.hyhthjk.com.cn/note.php/wx/Index4/index2', 
				data: {
				code:res.code   //从微信服务器得到的code 发给阿里云的服务器
				},
				header: {
				  'content-type': 'application/json' // 默认值
				},
				success: function (res) {
				  console.log(res.data)
				}
			  })
			}
		  })
		}
	  })
	  <hr/>
	  <h6>服务器部分</h6>
	  $code = input('get.code');
    // $this->logger($code);
    $appid = "wx3843c7001aba60e4";
    $secret = "8ba50984c338480a59566a6487e583f7";
    {literal}$api = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$secret}&js_code={$code}&grant_type=authorization_code";{/literal}
	  $ch = curl_init();                      //<span style="color:red"> 向微信服务器请求</span>
	  curl_setopt($ch, CURLOPT_URL,$api);
	  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
	  $data1 = curl_exec($ch);
    curl_close($ch);
    // $this->logger($data);
    
    $data = json_decode($data1,true);  
   if(isset($data['openid'])){
    $this->logger('获得的openid是：'.$data['openid']);
  
    }
	  </pre>


	<!--公共js区-->
	<script src="__ROOT__/static/js/jquery.min.js"></script>
	<script src="__ROOT__/static/js/bootstrap.min.js"></script>
</body>

</html>